<?php
require_once("socialnetwork.php");
require_once("osapi/osapi.php");

class MyspaceNetwork implements SocialNetwork {
    
    private $appKey = "f775a0f5dc7f4cf78dc1939ada087a86";
    private $appSecret = "10903a4ba7404efabb3e8da83b6df6b736629d5955794152b1742db075d6ea63";
    
    private $myspaceId;
    private $osapi;
    private $status;
    
    public function authenticate() {
        require_once("osapi/osapi.php");
        $storage = new osapiFileStorage('.temp-osapi');
        $provider = new osapiMySpaceProvider();
        session_start();
        $localUserId = session_id();

        

        $auth = osapiOAuth3Legged::performOAuthLogin($this->appKey, $this->appSecret, $storage, $provider, $_SESSION['user']);

        $this->osapi = new osapi($provider, $auth);

        session_start();
        $_SESSION['myspaceLoggedIn'] = true;
    }
    
    public function getStatus() {
        $osapi = new osapi(new osapiMySpaceProvider(), new osapiOAuth2Legged($this->appKey, $this->appSecret, $this->myspaceId));
        $batch = $osapi->newBatch();

    // Fetch the status mood MySpace specific.
        $batch->add($osapi->statusmood->get(array()), 'get_status_mood');

    // Send all batched commands
      $result = $batch->execute();  
      
      $this->status = new MyspaceStatus($result['get_status_mood']->status, 
                                        $result['get_status_mood']->moodStatusLastUpdated, 
                                        $result['get_status_mood']->moodName,
                                        $result['get_status_mood']->moodPictureUrl);
      return $this->status;
    }
    
    public function updateStatus() {
        
    }
    
    public function setMyspaceId($id) {
        $this->myspaceId = $id; 
    }
    
    public function getMyspaceId() {
        return $this->myspaceid;
    }
    
    public function getOsapi() {
        return $this->osapi;
    }
    
    public function getMyspaceUrl() {
        return "myspace.com/" . $this->myspaceId;
    }
}

class MyspaceStatus {
    private $status;
    private $date;
    private $mood;
    private $moodIconUrl;
    
    function __construct($status, $date, $mood, $moodIconUrl) {
        $this->status = $status;
        $this->date = $date;
        $this->mood = $mood;
        $this->moodIconUrl = $moodIconUrl;
    }

    public function getStatus() {
        return $this->status;
    }

    public function setStatus($status) {
        $this->status = $status;
    }

    public function getDate() {
        return $this->date;
    }

    public function setDate($date) {
        $this->date = $date;
    }

    public function getMood() {
        return $this->mood;
    }

    public function setMood($mood) {
        $this->mood = $mood;
    }

    public function getMoodIconUrl() {
        return $this->moodIconUrl;
    }

    public function setMoodIconUrl($moodIconUrl) {
        $this->moodIconUrl = $moodIconUrl;
    }
}

?>
